package com.fosu.dao;

import com.fosu.common.ResponseResult;
import com.fosu.domain.Product;
import com.fosu.domain.ProductCategories;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author zqa
 * @version 1.0
 * @date 2020/10/19 16:53
 */

@Mapper
@Repository
public interface CategoriesDao {

    /**查找所有分类
     * @return List<ProductCategories> 系统预设分类对象集合
     * @throws Exception
     */
    @Select("select * from  categories")
    @ResultMap(value = "categoriesMap")
    List<ProductCategories> findAll() throws Exception;


    /**
     * 获取标签表数据个数
     * @return int 标签表数据个数
     * @throws Exception
     */
    @Select("select count(*) from categories")
    int getDataCount() throws Exception;


    /**
     * 根据首页用户传入的商品id获得特定商品分类
     * @param productId 商品id
     * @return List<ProductCategories> 系统预设分类对象集合
     */
    @Select("select c.categories_id,c.categories_name " +
            "from product_categories pc,categories c " +
            "where pc.product_id=#{productId} " +
            "and pc.categories_id = c.categories_id")
    @Results(id = "categoriesMap", value = {
            @Result(property = "categoriesId", column = "categories_id"),
            @Result(property = "categoriesName", column = "categories_name")
    })
    List<ProductCategories> findCategoriesById(int productId);





}
